/**
 * Created with IntelliJ IDEA.
 * Description:自定义异常
 * User: 阿宾
 * Date: 2024-08-09
 * Time: 16:45
 */
public class LogIn {
    private String userName = "admin";
    private String password = "123456";

    public void loginInfo(String userName,String password) throws UserNameException,PasswordException{
        if(!this.userName.equals(userName)){
            throw new UserNameException("用户名有误");
        }
        if(!this.password.equals(password)){
            throw new PasswordException("密码有误");
        }
        System.out.println("登录成功");
    }

    public static void main(String[] args) {
        LogIn logIn = new LogIn();
        try{
            logIn.loginInfo("admin","123456");
        }catch (UserNameException e){
            e.printStackTrace();//定位代码出现的问题位置
            System.out.println("用户名不对");
        }catch (PasswordException e){
            e.printStackTrace();//定位代码出现的问题位置
            System.out.println("密码不对");
        }

    }
}
